package com.ruoyi.APPMS.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.APPMS.domain.Purchasevehicleorder;
import com.ruoyi.APPMS.service.IPurchasevehicleorderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 购买车辆订单管理Controller
 *
 * @author wanghaoyu
 * @date 2023-07-03
 */
@RestController
@RequestMapping("/purchasevehicleorder/purchasevehicleorder")
@Api(tags = "车辆采购订单控制器")
public class PurchasevehicleorderController extends BaseController {
    @Autowired
    private IPurchasevehicleorderService purchasevehicleorderService;

    /**
     * 查询购买车辆订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:list')")
    @GetMapping("/list")
    @ApiOperation("分页查询车辆采购订单信息")
    public TableDataInfo list(Purchasevehicleorder purchasevehicleorder) {
        startPage();
        List<Purchasevehicleorder> list = purchasevehicleorderService.list(purchasevehicleorder);
        return getDataTable(list);
    }

    /**
     * 导出购买车辆订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:export')")
    @Log(title = "购买车辆订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出车辆采购订单信息")
    public void export(HttpServletResponse response, Purchasevehicleorder purchasevehicleorder) {
        List<Purchasevehicleorder> list = purchasevehicleorderService.list(purchasevehicleorder);
        ExcelUtil<Purchasevehicleorder> util = new ExcelUtil<Purchasevehicleorder>(Purchasevehicleorder.class);
        util.exportExcel(response, list, "购买车辆订单管理数据");
    }

    /**
     * 获取购买车辆订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:query')")
    @GetMapping(value = "/{purchasevehicleorderid}")
    @ApiOperation("展示一条车辆采购订单信息")
    public AjaxResult getInfo(@PathVariable("purchasevehicleorderid") Long purchasevehicleorderid) {
        System.out.println(purchasevehicleorderService.listByID(purchasevehicleorderid));
        return success(purchasevehicleorderService.listByID(purchasevehicleorderid));
    }

    /**
     * 新增购买车辆订单管理
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:add')")
    @Log(title = "购买车辆订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("添加车辆采购订单信息")
    public AjaxResult add(@RequestBody Purchasevehicleorder purchasevehicleorder) {
        return toAjax(purchasevehicleorderService.save(purchasevehicleorder));
    }

    /**
     * 修改购买车辆订单管理
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:edit')")
    @Log(title = "购买车辆订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("发货")
    public AjaxResult edit(@RequestBody Purchasevehicleorder purchasevehicleorder) {
        purchasevehicleorderService.createLogistic1(purchasevehicleorder);
        purchasevehicleorderService.settime(purchasevehicleorder);
        return toAjax(purchasevehicleorderService.createLogistic2(purchasevehicleorder));
    }

    /**
     * 删除购买车辆订单管理
     */
    @PreAuthorize("@ss.hasPermi('purchasevehicleorder:purchasevehicleorder:remove')")
    @Log(title = "购买车辆订单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{purchasevehicleorderids}")
    @ApiOperation("删除车辆采购订单信息")
    public AjaxResult remove(@PathVariable List<Long> purchasevehicleorderids) {
        return toAjax(purchasevehicleorderService.removeByIds(purchasevehicleorderids));
    }
}
